<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2018/12/11
 * Time: 17:52
 */
namespace common\sources\write\category;

use Yii;
use common\models\craftsman\Category;

class CategoryAccess implements ICategoryAccess
{

    public function addCategory($data)
    {
        $insert = 'INSERT INTO category (name,pid,status,create_time)
                   VALUES (:name,:pid,:status,:create_time)';
        return Yii::$app->db->createCommand($insert )->bindValues([
            ':name' => $data['name'],
            ':pid'=>$data['pid'],
            ':status'=> 0,
            ':create_time'=>time()
        ])->execute();
    }
    public function modifyCategory($data)
    {
        $sql = 'UPDATE ' . Category::tableName() . ' SET name = :name,pid =:pid,update_time = :update_time WHERE id = :id ';
        return Yii::$app->db->createCommand($sql)
            ->bindValues([
                ':name' => $data['cate_name'],
                'pid' => $data['pid'],
                ':update_time' => time(),
                ':id' => $data['cate_id']
            ])->execute();
    }
    public function delCategory($data)
    {
        return Yii::$app->db->createCommand()->delete(Category::tableName(), 'id = '.$data['cate_id'])->execute();
    }
}